﻿using System.Web;

namespace CRMWeb.Utilities.Context
{
    public static class SessionHelper
    {
        public static object GetValue(string key)
        {
            //if (!SessionHelper.AllowSessionState || HttpContext.Current == null || HttpContext.Current.Session == null)
            if (HttpContext.Current == null || HttpContext.Current.Session == null)
            {
                return null;
            }
            return HttpContext.Current.Session[key];
        }

        public static void SetValue(string key, object value)
        {
            SetValue(key, value, false);
        }

        // Overload
        public static void SetValue(string key, object value, bool allowVirtualContext)
        {
            //if (!SessionHelper.AllowSessionState || HttpContext.Current == null || HttpContext.Current.Session == null || (VirtualContext.IsInitialized && !allowVirtualContext))
            if (HttpContext.Current == null || HttpContext.Current.Session == null)
            {
                return;
            }
            HttpContext.Current.Session[key] = value;
        }

        public static void Abandon()
        {
            //if (!SessionHelper.AllowSessionState || HttpContext.Current == null || HttpContext.Current.Session == null || VirtualContext.IsInitialized)
            if (HttpContext.Current == null || HttpContext.Current.Session == null)
            {
                return;
            }
            HttpContext.Current.Session.Abandon();
        }
    }
}